package com.situ.student.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.situ.student.dao.IUserDao;
import com.situ.student.util.JDBCUtil;

public class UserDaoImpl implements IUserDao {
	
	@Override
	public String login(String name, String password) {
		Connection connection = null;
		PreparedStatement preparedStatement = null;
		ResultSet resultSet = null;
		String count = null;
		try {
			connection = JDBCUtil.getConnection();
			String sql = "select * from user where name=? and password=?";
			preparedStatement = connection.prepareStatement(sql);
			preparedStatement.setString(1, name);
			preparedStatement.setString(2, password);
			resultSet = preparedStatement.executeQuery();
			while (resultSet.next()) {
				count = resultSet.getString(1);
			}
			System.out.println("count="+count);
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			JDBCUtil.close(connection, preparedStatement, resultSet);
		}

		return count;
	}
}
